import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class text {
    public static void main(String[] args) {
        try {
            // 1. 创建目标地址URL对象
            URL url = new URL("http://192.168.0.253:6109/gslock/api/autoquhao");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            // 2. 配置请求参数
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            connection.setRequestProperty("Accept", "application/json");
            connection.setDoOutput(true);
            connection.setDoInput(true);

            // 3. 构建JSON请求体（手动拼接）
            String jsonBody = "{"
                    + "\"haoliebiao\": [{"
                    +   "\"lockclass\": \"鞋柜\","
                    +   "\"guibin\": \"男宾\","
                    +   "\"shuliang\": 1,"
                    +   "\"xiaohai\": 0,"
                    +   "\"guanliquming\": \"男宾鞋柜\","
                    +   "\"uuid\": \"EX118813\""
                    + "}],"
                    + "\"token\": \"+36baL9JGC9G1VnQZaW/22yxiomD1SolOgQOAl21k6ayjpmp+SI0DljicYfBkqm7gtHeds0=\""
                    + "}";

            // 4. 发送请求
            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonBody.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            // 5. 处理响应
            int statusCode = connection.getResponseCode();
            System.out.println("HTTP 状态码: " + statusCode);

            if (statusCode == HttpURLConnection.HTTP_OK) {
                try (BufferedReader br = new BufferedReader(
                        new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
                    StringBuilder response = new StringBuilder();
                    String responseLine;
                    while ((responseLine = br.readLine()) != null) {
                        response.append(responseLine.trim());
                    }
                    System.out.println("服务器响应: " + response);
                }
            } else {
                System.err.println("请求失败，错误码: " + statusCode);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}